 /*********************************************************************
 *
 *	Hardware specific definitions for:
 *    - PIC18 Explorer
 *    - PIC18F8722 and other PIC18s
 *    - Ethernet PICtail (ENC28J60)
 *
 *********************************************************************
 * FileName:        HardwareProfile.h
 * Dependencies:    Compiler.h
 * Processor:       PIC18
 * Compiler:        Microchip C18 v3.36 or higher
 * Company:         Microchip Technology, Inc.
 *
 * Software License Agreement
 *
 * Copyright (C) 2002-2010 Microchip Technology Inc.  All rights
 * reserved.
 *
 * Microchip licenses to you the right to use, modify, copy, and
 * distribute:
 * (i)  the Software when embedded on a Microchip microcontroller or
 *      digital signal controller product ("Device") which is
 *      integrated into Licensee's product; or
 * (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h,
 *		ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device
 *		used in conjunction with a Microchip ethernet controller for
 *		the sole purpose of interfacing with the ethernet controller.
 *
 * You should refer to the license agreement accompanying this
 * Software for additional information regarding your rights and
 * obligations.
 *
 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
 *
 *
 * Author               Date		Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Howard Schlunder		09/16/2010	Regenerated for specific boards
 ********************************************************************/
#ifndef HARDWARE_PROFILE_H
#define HARDWARE_PROFILE_H

#include "Compiler.h"
#include "C:\ProjetoPic\Libraries\TCPIP\Demo App\MPLAB.X\LCDCustom.h"

// Define a macro describing this hardware set up (used in other files)
#define PIC18_EXPLORER

// Set configuration fuses (but only in MainDemo.c where THIS_IS_STACK_APPLICATION is defined)
#if defined(THIS_IS_STACK_APPLICATION)
	#if defined(__18F8722)
		#pragma config OSC=HSPLL, FCMEN=OFF, IESO=OFF, PWRT=OFF, WDT=OFF, LVP=OFF
	#elif defined(__18F87J10)
		#pragma config WDTEN=OFF, FOSC2=ON, FOSC=HSPLL
	#elif defined(__18F87J11)
		#pragma config WDTEN=OFF, FOSC=HSPLL
	#elif defined(__18F87J50)
		#pragma config WDTEN=OFF, FOSC=HSPLL, PLLDIV=3, CPUDIV=OSC1
       #endif

	// Automatically set Extended Instruction Set fuse based on compiler setting
	#if defined(__EXTENDED18__)
		#pragma config XINST=ON
	#else
		#pragma config XINST=OFF, LVP=OFF, OSC=INTIO67
	#endif
#endif


// Clock frequency values
// These directly influence timed events using the Tick module.  They also are used for UART and SPI baud rate generation.
#if defined(__18F87J50) || defined(_18F87J50)
	#define GetSystemClock()	(48000000ul)			// PIC18F87J50 USB PIM has it's own 12MHz crystal on it
#else	// PIC18F8722, PIC18F87J11, other ordinary PIMs	// Uses 10MHz crystal on PIC18 Explorer
	#define GetSystemClock()	(32000000ul)			// Hz
#endif
#define GetInstructionClock()	(GetSystemClock()/4)	// Should be GetSystemClock()/4 for PIC18
#define GetPeripheralClock()	(GetSystemClock()/4)	// Should be GetSystemClock()/4 for PIC18


// Hardware I/O pin mappings

 /*  LCD Module I/O pins *******************************************/

#if !defined(LCD_DATA0_TRIS	)


#define LCD_DATA0_TRIS		(TRISDbits.TRISD0)		// Multiplexed with LED6
#define LCD_DATA0_IO		(LATDbits.LATD0)
#define LCD_DATA1_TRIS		(TRISDbits.TRISD1)
#define LCD_DATA1_IO		(LATDbits.LATD1)
#define LCD_DATA2_TRIS		(TRISDbits.TRISD2)
#define LCD_DATA2_IO		(LATDbits.LATD2)
#define LCD_DATA3_TRIS		(TRISDbits.TRISD3)		// Multiplexed with LED3
#define LCD_DATA3_IO		(LATDbits.LATD3)
#define LCD_DATA4_TRIS		(TRISDbits.TRISD4)		// Multiplexed with LED2
#define LCD_DATA4_IO		(LATDbits.LATD4)
#define LCD_DATA5_TRIS		(TRISDbits.TRISD5)
#define LCD_DATA5_IO		(LATDbits.LATD5)
#define LCD_DATA6_TRIS		(TRISDbits.TRISD6)
#define LCD_DATA6_IO		(LATDbits.LATD6)
#define LCD_DATA7_TRIS		(TRISDbits.TRISD7)
#define LCD_DATA7_IO		(LATDbits.LATD7)
#define LCD_RD_WR_TRIS		(TRISAbits.TRISA2)
#define LCD_RD_WR_IO		(LATAbits.LATA2)
#define LCD_RS_TRIS			(TRISAbits.TRISA1)
#define LCD_RS_IO			(LATAbits.LATA1)
#define LCD_E_TRIS			(TRISAbits.TRISA3)
#define LCD_E_IO	

#endif

// LEDs
#define LED0_TRIS			(TRISDbits.TRISD0)	// Ref D1
#define LED0_IO				(LATDbits.LATD0)
#define LED1_TRIS			(TRISDbits.TRISD1)	// Ref D2
#define LED1_IO				(LATDbits.LATD1)
#define LED2_TRIS			(TRISDbits.TRISD2)	// Ref D3
#define LED2_IO				(LATDbits.LATD2)
#define LED3_TRIS			(TRISDbits.TRISD3)	// Ref D4
#define LED3_IO				(LATDbits.LATD3)
#define LED4_TRIS			(TRISDbits.TRISD4)	// Ref D5
#define LED4_IO				(LATDbits.LATD4)
#define LED5_TRIS			(TRISDbits.TRISD5)	// Ref D6
#define LED5_IO				(LATDbits.LATD5)
#define LED6_TRIS			(TRISDbits.TRISD6)	// Ref D7
#define LED6_IO				(LATDbits.LATD6)
#define LED7_TRIS			(TRISDbits.TRISD7)	// Ref D8
#define LED7_IO				(LATDbits.LATD7)
#define LED_GET()			(LATD)
#define LED_PUT(a)			(LATD = (a))

// Sensores
#define DHT11_TRIS                      TRISCbits.TRISC7
#define DHT11_PIN                       PORTCbits.RC7
#define S_MOVE_TRIS                      TRISBbits.TRISB6
#define S_MOVE_IO                       PORTBbits.RB6
#define S_CHAMAS_TRIS                      TRISBbits.TRISB7
#define S_CHAMAS_IO                       PORTBbits.RB7
#define S_LUM_TRIS                      TRISBbits.TRISB0 //RE0
#define S_LUM_IO                       PORTBbits.RB0
#define S_TILT_TRIS                      TRISBbits.TRISB1 //RE1
#define S_TILT_IO                       PORTBbits.RB1
//#define S_PORT_TRIS                      TRISBbits.TRISB2 //RE2
//#define S_PORT_IO                       PORTBbits.RB2

// ADC
#define AN0_TRIS		(TRISAbits.TRISA0)
#define	AN0_IO			(PORTAbits.RA0)
#define AN1_TRIS		(TRISAbits.TRISA1)
#define	AN1_IO			(PORTAbits.RA1)
#define AN2_TRIS		(TRISAbits.TRISA2)
#define	AN2_IO			(PORTAbits.RA2)


// Momentary push buttons
//#define BUTTON0_TRIS		(TRISCbits.TRISC6)
//#define	BUTTON0_IO			(PORTCbits.RC6)
//#define BUTTON2_TRIS		(TRISCbits.TRISC2)
//#define	BUTTON2_IO			(PORTCbits.RC2)



// ENC28J60 I/O pins
#define ENC_RST_TRIS		(TRISCbits.TRISC0)
#define ENC_RST_IO			(LATCbits.LATC0)
#define ENC_CS_TRIS			(TRISCbits.TRISC1)
#define ENC_CS_IO			(LATCbits.LATC1)
#define ENC_SCK_TRIS		(TRISCbits.TRISC3)
#define ENC_SDI_TRIS		(TRISCbits.TRISC4)
#define ENC_SDO_TRIS		(TRISCbits.TRISC5)
#define ENC_SPI_IF			(PIR1bits.SSPIF)
#define ENC_SSPBUF			(SSPBUF)
#define ENC_SPISTAT			(SSPSTAT)
#define ENC_SPISTATbits		(SSPSTATbits)
#define ENC_SPICON1			(SSPCON1)
#define ENC_SPICON1bits		(SSPCON1bits)
#define ENC_SPICON2			(SSPCON2)

// Teclado 4x5 COnsiderando contatos secos

#define KEY_LINE1_TRIS          (TRISEbits.TRISE0) //RB0
#define KEY_LINE1_IO            (LATEbits.LATE0)
#define KEY_LINE2_TRIS          (TRISEbits.TRISE1)//RB1
#define KEY_LINE2_IO            (LATEbits.LATE1)
#define KEY_LINE3_TRIS          (TRISEbits.TRISE2) //RB2
#define KEY_LINE3_IO            (LATEbits.LATE2)
#define KEY_LINE4_TRIS          (TRISCbits.TRISC2) //RB3
#define KEY_LINE4_IO            (LATCbits.LATC2)
#define KEY_LINE5_TRIS          (TRISBbits.TRISB4) //RB4
#define KEY_LINE5_IO            (LATBbits.LATB4)

#define KEY_COL1_TRIS           (TRISAbits.TRISA4)
#define KEY_COL1_IO             (PORTAbits.RA4)
#define KEY_COL2_TRIS           (TRISAbits.TRISA5)
#define KEY_COL2_IO             (PORTAbits.RA5)
#define KEY_COL3_TRIS           (TRISAbits.TRISA6)
#define KEY_COL3_IO             (PORTAbits.RA6)
#define KEY_COL4_TRIS           (TRISAbits.TRISA7)
#define KEY_COL4_IO             (PORTAbits.RA7)

#define KEYBOARD_OUT            (PORTA)

//Saidas

#define ABERTURA_PORTA_TRIS     (TRISBbits.TRISB5)
#define ABERTURA_PORTA_IO     (LATBbits.LATB5)


// Register name fix up for certain processors
#define SPBRGH			SPBRGH1
#if defined(__18F87J50) || defined(_18F87J50) || defined(__18F87J11) || defined(_18F87J11)
	#define ADCON2		ADCON1
#endif

// UART mapping functions for consistent API names across 8-bit and 16 or 
// 32 bit compilers.  For simplicity, everything will use "UART" instead 
// of USART/EUSART/etc.
#define BusyUART()			BusyUSART()
#define CloseUART()			CloseUSART()
#define ConfigIntUART(a)	ConfigIntUSART(a)
#define DataRdyUART()		DataRdyUSART()
#define OpenUART(a,b,c)		OpenUSART(a,b,c)
#define ReadUART()			ReadUSART()
#define WriteUART(a)		WriteUSART(a)
#define getsUART(a,b,c)		getsUSART(b,a)
#define putsUART(a)			putsUSART(a)
#define getcUART()			ReadUSART()
#define putcUART(a)			WriteUSART(a)
#define putrsUART(a)		putrsUSART((far rom char*)a)

#endif // #ifndef HARDWARE_PROFILE_H
